<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="物料名称" prop="vSpaName">
        <el-input
          v-model="queryParams.vSpaName"
          placeholder="请输入物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="规格型号" prop="vSpaModel">
        <el-input
          v-model="queryParams.vSpaModel"
          placeholder="请输入规格型号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="品牌" prop="vSpaBrand">
        <el-input
          v-model="queryParams.vSpaBrand"
          placeholder="请输入品牌"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同编号" prop="vBillNo">
        <el-input
          v-model="queryParams.vBillNo"
          placeholder="请输入合同编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="项目号" prop="vProjectNo">
        <el-input
          v-model="queryParams.vProjectNo"
          placeholder="请输入项目号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商" prop="supplier">
        <el-input
          v-model="queryParams.supplier"
          placeholder="请输入供应商"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="postList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="合同号" prop="vBillNo" align="center" />
      <el-table-column label="项目号" prop="vProjectNo" align="center" />
      <el-table-column label="物料名称/零件名" prop="vSpaName" align="center" />
      <el-table-column
        label="规格型号/图纸号"
        prop="vSpaModel"
        align="center"
      />
      <el-table-column label="品牌/材料" prop="vSpaBrand" align="center" />
      <el-table-column label="供应商/厂家" prop="supplier" align="center" />
      <el-table-column label="单位" prop="vUnit" width="50px" align="center" />
      <el-table-column label="数量" align="center" prop="nQty" />
      <!-- <el-table-column label="已发货数量" align="center" prop="nPostQty">
        <template slot-scope="scope">
          <el-button type="text" @click="toPostQty(scope.row)">
            {{ scope.row.nPostQty }}</el-button
          >
        </template>
      </el-table-column> -->
      <el-table-column label="已入库数量" align="center" prop="nINWHQty">
        <template slot-scope="scope">
          <el-button type="text" @click="toINWHQty(scope.row)">
            {{ scope.row.nINWHQty }}</el-button
          >
        </template>
      </el-table-column>
      <el-table-column label="已开发票数量" align="center" prop="nInvQty">
        <template slot-scope="scope">
          <el-button type="text" @click="toInvQty(scope.row)">
            {{ scope.row.nInvQty }}</el-button
          >
        </template>
      </el-table-column>
      <el-table-column
        label="备注"
        width="100px"
        prop="remark"
        align="center"
      />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog
      title="库存动态"
      :visible.sync="kucunOpen"
      width="1000px"
      append-to-body
    >
      <el-table :data="kucunList" height="500px">
        <el-table-column label="物料名称" align="center" prop="vSpaName" />
        <el-table-column label="规格型号" align="center" prop="vSpaModel" />
        <el-table-column label="数量" align="center" prop="nQty" />
        <el-table-column label="入出库类型" align="center" prop="iotype">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.inv_iotpye"
              :value="scope.row.iotype"
            />
          </template>
        </el-table-column>
        <el-table-column label="单据类型" align="center" prop="vType">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.inv_bill_type"
              :value="scope.row.vType"
            />
          </template>
        </el-table-column>
        <el-table-column label="成本单价" align="center" prop="nPrice" />
        <el-table-column label="对应单编号" align="center" prop="vCorBillNo" />
        <el-table-column label="对应项目" align="center" prop="vProjectNo" />
      </el-table>
    </el-dialog>

    <el-dialog
      title="物流明细"
      :visible.sync="wuliuOpen"
      width="1000px"
      append-to-body
    >
      <el-table :data="wuliuList" height="500px">
        <el-table-column label="物料名称" align="center" prop="vSpaName" />
        <el-table-column label="规格型号" align="center" prop="vSpaModel" />
        <el-table-column label="数量" align="center" prop="nQty" />
        <el-table-column label="单据编号" align="center" prop="vBillNo" />
        <el-table-column label="邮递编号" align="center" prop="vPostNo" />
        <el-table-column label="邮递方式" align="center" prop="vPostType">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.buy_post_type"
              :value="scope.row.vPostType"
            />
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <el-dialog
      title="发票明细"
      :visible.sync="fapiaoOpen"
      width="1000px"
      append-to-body
    >
      <el-table :data="fapiaoList" height="500px">
        <el-table-column
          label="物料名称/零件名"
          align="center"
          prop="vSpaName"
        />
        <el-table-column
          label="规格型号/图纸号"
          align="center"
          prop="vSpaModel"
        />
        <el-table-column label="数量" align="center" prop="nQty" />
        <!-- <el-table-column label="单价" align="center" prop="vBillNo" /> -->
        <el-table-column label="发票编号" align="center" prop="vInvocieNo" />
        <el-table-column label="发票代码" align="center" prop="vInvocieCode" />
        <el-table-column label="发票金额" align="center" prop="nAmt" />
        <el-table-column label="发票税率" align="center" prop="nTax" />
        <el-table-column label="开票时间" align="center" prop="dInvocie" />
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import { listInv0004New } from "@/api/inv/inv0004";
import { getViewData } from "@/api/inv/inv0002";
import { getPostData, getInvData } from "@/api/buy/buy0005";
export default {
  name: "buy0005",

  dicts: [
    "sys_common_status",
    "inv_arrival_status",
    "buy_post_type",
    "inv_bill_type",
    "inv_iotpye",
  ],
  data() {
    return {
      flag: false,
      // 遮罩层
      loading: true,
      arrivalOpen: false,
      executeOpen: false,
      printOpen: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 采购邮寄表格数据
      postList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        vBillNo: null, //合同号
        vProjectNo: null,
        vSpaName: null,
        vSpaModel: null,
        vSpaBrand: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      kucunOpen: false,
      kucunList: [],
      wuliuOpen: false,
      wuliuList: [],
      fapiaoOpen: false,
      fapiaoList: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询采购邮寄列表 */
    getList() {
      this.loading = true;
      listInv0004New(this.queryParams).then((response) => {
        this.postList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    toINWHQty(row) {
      getViewData(row).then((response) => {
        this.kucunList = response.data;
        this.kucunOpen = true;
      });
    },

    toPostQty(row) {
      getPostData(row).then((response) => {
        this.wuliuList = response.data;
        this.wuliuOpen = true;
      });
    },

    toInvQty(row) {
      getInvData(row).then((response) => {
        this.fapiaoList = response.data;
        this.fapiaoOpen = true;
      });
    },
  },
};
</script>
